package LearnWork;

//2014-8-8 Map Key取值

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class MapGetValue {

	public static void main(String[] args) {
		Map<Integer, Integer> myMap = new HashMap<Integer, Integer>();
		int n = 100;

		for (int i = 0; i < n; i++) {
			myMap.put(i, ((int) (Math.random() * 10)));
		}

		Set keys = myMap.keySet();
		if (keys != null) {
			//把所有的KEY取出來，直到沒有這個KEY
			Iterator iterator = keys.iterator();
			while (iterator.hasNext()) {
				//.next方法代表 map的key還有可以取出來
				Object key = iterator.next();
				Object value = myMap.get(key);
				System.out.println(key.toString() + "-" + value.toString());
			}
		}
		
		//可以把MAP所有資料印出來
		System.out.println(myMap.entrySet());
	}
}
